<?php
/**
 * Created by JetBrains PhpStorm.
 * User: akrug
 * Date: 19.01.12
 * Time: 10:08
 * To change this template use File | Settings | File Templates.
 */
class Zend_View_Helper_RadiobuttonHelper {

    /**
     * Radio-Buttons Formatieren, label nach dem input-Feld
     *
     * @param $element
     * @return string
     */
    public function RadiobuttonHelper($element, $check = null){

        $radioContent = "";
        $multioptions = $element->getMultioptions();
        //sind multioptions vorhanden
        if(!empty($multioptions)){
            // Input-Elemente splitten
            $elements = explode('<br />', $element->render());
            // Input-Felder durchlaufen
            foreach($elements as $eIndex => $e) {
                // HTML bearbeiten
                $htmlTags = explode(">", $e);

                if(null != $check){
                    $radioContent .= $htmlTags[0].">".$htmlTags[2].">".$htmlTags[1].">";
                }else{
                    $radioContent .= $htmlTags[1].">".$htmlTags[0].">".$htmlTags[2].">";
                }

                if($eIndex < sizeof($elements)-1 && null != $check) $radioContent .= " <br /> ";
            }

            if($element->hasErrors()){
               $errors = $element->getErrors();
               $layout = Zend_Layout::getMvcInstance();
               $view = $layout->getView();
               $radioContent .= $view->FormErrors($errors);
            }
        }
        return $radioContent;
    }
}
